package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

/**
 * Des:
 * TODO *****
 * @author XL
 * @Date 2022/5/9 10:53
 */
public class 二叉搜索树的范围和938 {
    int ans;
    int l;
    int h;
    public int rangeSumBST(TreeNode root, int low, int high) {
        l = low;
        h = high;
        recur(root);
        return ans;
    }

    public void recur(TreeNode node) {
        if (node == null) return;
        if (node.val > h) {
            recur(node.left);
        }else if (node.val < l) {
            recur(node.right);
        }else {
            ans = ans + node.val;
            recur(node.left);
            recur(node.right);
        }
    }
}
